package com.test.nio.demo02;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class SocketChannelDemo {

	void startClient() throws IOException {
		SocketChannel socketChannel = SocketChannel.open();
		socketChannel.connect(new InetSocketAddress("localhost", 8999));
		socketChannel.configureBlocking(false);

		String request = "Hello ServerSocketChannel";
		ByteBuffer buff = ByteBuffer.wrap(request.getBytes("UTF-8"));
		socketChannel.write(buff);
		buff.clear();
		socketChannel.close();
	}

	public static void main(String[] args) throws IOException {
		new SocketChannelDemo().startClient();
	}
}
